// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Flapping Door Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 58 : TYPE_FLAPPINGDOOR

// Function declarations
reserve function FlappingDoor_DebugDraw
reserve function FlappingDoor_DebugSpawn

// Static Values

// Tables

function FlappingDoor_DebugDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
end function


function FlappingDoor_DebugSpawn
	CreateTempObject(TypeName[Flapping Door], 0, object.xpos, object.ypos)
	object[tempObjectPos].direction = object.direction
	object[tempObjectPos].value1 = 56
	object[tempObjectPos].value0 = 56
end function


event ObjectMain
	switch object.frame
	case 0
		if object[0].xpos < object.xpos
			CurrentTunnel_value33 = 4
		end if
	case 1
		object.value0--
		if object.value0 == -1
			temp0 = screen.cameraX
			temp0 -= object.ixpos
			temp0 -= 8
			Abs(temp0)
			if temp0 <= screen.xcenter
				temp0 = screen.cameraY
				temp0 -= object.iypos
				temp0 -= 32
				Abs(temp0)
				if temp0 <= screen.ycenter
					PlaySfx(SfxName[Flapping Door], 0)
				end if
			end if
		end if
		if object.value0 == -5
			object.value2 = 0
			object.frame = 2
		end if
		break
	case 2
		object.value2++
		if object.value2 == 4
			object.value3 ^= 1
			object.frame = object.value3
			object.value0 = object.value1
		end if
		break
	end switch
	if object.frame == 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			CheckEqual(object[currentPlayer].state, PlayerObject_HandleMonikaTeleport)
			temp7 = checkResult
			CheckLower(object[0].value1, 20)
			temp7 &= checkResult
			if temp7 == 0			
				BoxCollisionTest(C_BOX, object.entityPos, -8, -32, 8, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			end if
					
		next
	end if
end event


event ObjectDraw
	DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
end event


event ObjectStartup
	LoadSpriteSheet("LZ/Objects.gif")
	SpriteFrame(-8, -32, 16, 64, 1, 191)
	SpriteFrame(0, -40, 32, 80, 51, 175)
	SpriteFrame(-5, -38, 32, 76, 18, 179)
	foreach (TypeName[Flapping Door], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = object[arrayPos0].propertyValue
		object[arrayPos0].value1 *= 60
		object[arrayPos0].value1 -= 4
		object[arrayPos0].value0 = object[arrayPos0].value1
	next
	SetTableValue(TypeName[Flapping Door], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(FlappingDoor_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(FlappingDoor_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
